package com.test.mvcframework.pojo.handler;

import javax.servlet.http.HttpServletRequest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 处理器映射器
 * @author felix
 */
public class DefaultHandlerMapping implements HandlerMapping {
    private HandlerExecutionChain handler;

    private Pattern pattern;

    public DefaultHandlerMapping(HandlerExecutionChain handler, Pattern pattern) {
        this.handler = handler;
        this.pattern = pattern;
    }

    @Override
    public HandlerExecutionChain getHandler() {
        return handler;
    }

    @Override
    public boolean match(HttpServletRequest request) {
        String url = request.getRequestURI();
        Matcher matcher = pattern.matcher(url);
        return matcher.matches();
    }
}
